<?php

include("../class/connection.php");
$conexionSintomas = new Connection();
$conexionSintomas->connect();
$consultaId = $_GET['consultaId'];
$sql_pacientes = "SELECT *FROM Consulta
    INNER JOIN Sintomas_consulta ON Sintomas_consulta.Consulta_idConsulta= Consulta.idConsulta
    INNER JOIN Sintomas ON Sintomas.idSintoma=Sintomas_consulta.Sintomas_idSintoma
    WHERE Consulta.idConsulta=" . $consultaId;

$qry_pacienteSintomas = $conexionSintomas->executeQuery($sql_pacientes);


$sql_sintomas = "SELECT *FROM Sintomas";
$qry_sintomas = $conexionSintomas->executeQuery($sql_sintomas);
echo "<table width='100%' border='0'><tr><td width='45%'>";
echo "<u><b>Sintomas:</b></u>";
echo "<div id='div_sintomas' style='border: 1px coral solid;width:100%; height:230px;overflow:auto;'>";
echo "<TABLE>";
$id=0;
while ($reg_sintomas = mysql_fetch_assoc($qry_sintomas)) {
    $codigo_sintoma = $reg_sintomas['idSintoma'];
    echo "<tr><td>";
    $encontrado = 0;
    $qry_pacienteSintomas = $conexionSintomas->executeQuery($sql_pacientes);

    while ($reg_browsesintoma = mysql_fetch_assoc($qry_pacienteSintomas)) {
        if ($codigo_sintoma == $reg_browsesintoma['Sintomas_idSintoma']) {
            $encontrado = 1;
        }
    }
    $id++;
    echo "<input type='checkbox' value='" . $codigo_sintoma . "' id='chkSintoma".$id."' ";
    if ($encontrado == 1) {
        echo "disabled";
    }
    echo ">";
    echo "</td>";
    echo "<TD>" . $reg_sintomas['Sintoma'] . "</TD></TR>";
}

echo "</TABLE>";
echo "</div>";
echo "</td><td width='10%'>";
echo "<input type='button' value='>' onclick='agregar_sintomas(".$consultaId.")'><br/>";
echo "<div id='div_cargando_addsintoma'></div>";
echo "<input type='button' value='<' onclick='quitar_sintomas(".$consultaId.")'>";
echo "</td><td width='45%'>";
echo "<u><b>Sintomas->paciente:</b></u>";
echo "<div id='div_sintomas' style='border: 1px coral solid;width:100%; height:230px;overflow:auto;'>";
echo "<TABLE>";
$qry_pacienteSintomas = $conexionSintomas->executeQuery($sql_pacientes);
$id2=0;
while ($reg_sintomas_paciente = mysql_fetch_assoc($qry_pacienteSintomas)) {
    echo "<TR><td>";
    $id2=$id2+1;
    echo "<input type='checkbox' value='".$reg_sintomas_paciente['Sintomas_idSintoma']."' id='chkSintomaPaciente".$id2."'>";
    echo "</td>";
    echo "<TD>" . $reg_sintomas_paciente['Sintoma'] . "</TD></TR>";
}
echo "</TABLE>";
echo "</div>";
echo "</td><tr>";
echo "</table>";
?>
